<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>刺激提取工具</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            display: flex;
            flex-direction: column;
            height: 100vh;
            background-color: #f5f5f5;
        }
        .header {
            background-color: #333;
            color: white;
            padding: 10px 20px;
            font-size: 18px;
        }
        .content {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            padding: 20px;
            overflow: auto;
        }
        .image-container {
            position: relative;
            margin: 10px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.2);
            background-color: #fff;
            border-radius: 4px;
            overflow: hidden;
        }
        img {
            display: block;
            max-width: 100%;
            cursor: crosshair;
        }
        .point {
            position: absolute;
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background-color: red;
            border: 2px solid white;
            transform: translate(-50%, -50%);
            pointer-events: none;
        }
        .instructions {
            margin: 20px;
            padding: 10px 20px;
            background-color: #e7f3fe;
            border-left: 4px solid #2196F3;
            border-radius: 4px;
        }
        .button-container {
            margin: 20px 0;
        }
        button {
            padding: 10px 20px;
            font-size: 16px;
            border: none;
            border-radius: 4px;
            background-color: #4CAF50;
            color: white;
            cursor: pointer;
            margin: 0 5px;
        }
        button:hover {
            background-color: #45a049;
        }
        button:disabled {
            background-color: #cccccc;
            cursor: not-allowed;
        }
        #cancelBtn {
            background-color: #f44336;
        }
        #cancelBtn:hover {
            background-color: #d32f2f;
        }
        .status-container {
            margin: 20px 0;
            padding: 15px;
            border-radius: 4px;
            background-color: #fff3cd;
            border-left: 4px solid #ffc107;
            display: none;
        }
        .spinner {
            border: 4px solid rgba(0, 0, 0, 0.1);
            width: 24px;
            height: 24px;
            border-radius: 50%;
            border-left-color: #09f;
            display: inline-block;
            margin-right: 10px;
            animation: spin 1s linear infinite;
        }
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body>
    <div class="header">
        刺激提取工具
    </div>
    <div class="content">
        <div class="instructions">
            <h3>使用说明：</h3>
            <p>请在图像上点击LED发光二极管的位置。系统将分析视频中每一帧该位置附近的亮度变化，判断是否存在刺激。</p>
        </div>
        <div class="image-container">
            <img id="frameImage" src="{IMAGE_DATA}" alt="视频第一帧">
            <div id="point" class="point" style="display: none;"></div>
        </div>
        <div class="status-container" id="processingStatus">
            <div class="spinner"></div>
            <span id="statusText">正在处理视频帧，请稍候...</span>
        </div>
        <div class="button-container">
            <button id="confirmBtn" disabled>确认选择</button>
            <button id="cancelBtn">取消</button>
        </div>
    </div>

    <script>
        let selectedPoint = null;
        const frameImage = document.getElementById('frameImage');
        const pointMarker = document.getElementById('point');
        const confirmBtn = document.getElementById('confirmBtn');
        const cancelBtn = document.getElementById('cancelBtn');
        const processingStatus = document.getElementById('processingStatus');
        const statusText = document.getElementById('statusText');

        frameImage.addEventListener('click', function(e) {
            const rect = frameImage.getBoundingClientRect();
            const x = e.clientX - rect.left;
            const y = e.clientY - rect.top;
            
            selectedPoint = [x, y];
            
            // 显示选择点
            pointMarker.style.left = x + 'px';
            pointMarker.style.top = y + 'px';
            pointMarker.style.display = 'block';
            
            // 启用确认按钮
            confirmBtn.disabled = false;
        });

        confirmBtn.addEventListener('click', function() {
            if (selectedPoint) {
                // 禁用按钮，防止重复点击
                confirmBtn.disabled = true;
                cancelBtn.disabled = true;
                
                // 将选择点传递给Rust
                window.external.invoke(JSON.stringify(selectedPoint));
            }
        });

        cancelBtn.addEventListener('click', function() {
            window.close();
        });

        // 显示处理中状态
        function showProcessing() {
            frameImage.style.opacity = '0.5';
            processingStatus.style.display = 'block';
            confirmBtn.disabled = true;
            cancelBtn.disabled = true;
        }

        // 处理完成
        function processingComplete() {
            processingStatus.style.display = 'none';
            statusText.innerText = '处理完成，正在返回结果...';
        }
    </script>
</body>
</html> 